package com.ruoyi.web.controller.eventbus.bigdata;

import com.github.pagehelper.PageHelper;
import com.google.common.eventbus.Subscribe;
import com.ruoyi.common.utils.CacheUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import com.ruoyi.web.controller.eventbus.EventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;


@Component
public class BigDataSerachEventBus implements EventListener {

    @Autowired
    private IROrgRiskEventService rOrgRiskEventService;


    private static final Logger log = LoggerFactory.getLogger(BigDataSerachEventBus.class);
    @Subscribe
    public void cacheQuery(SearchEvent searchEvent)  {
        log.info("Subscribe::searchEventID:{}",searchEvent.getOrgId());
        if(Objects.nonNull(searchEvent.getOrgId())){
            //风险事件
            removeCache(CacheUtils.EVENT_KEY+searchEvent.getOrgId());
//            PageHelper.startPage(1,20);
//            ROrgRiskEvent rOrgRiskEvent = new ROrgRiskEvent();
//            rOrgRiskEvent.setOrgId(searchEvent.getOrgId());
//            List<ROrgRiskEvent> rOrgRiskEvents = rOrgRiskEventService.selectROrgRiskEventList(rOrgRiskEvent);
//            CacheUtils.put(CacheUtils.EVENT_KEY+searchEvent.getOrgId(),rOrgRiskEvents);

        }

    }


    public void  removeCache(String key){
        if(Objects.nonNull(CacheUtils.get(key))){
            CacheUtils.remove(key);
        }
    }
}
